#include <gtest/gtest.h>
#include "../../types.h"

void test_area_cells_borders( double sizex, double sizey, double sizez ) {
    Area_size area_size = { sizex, sizey, sizez };
    double split_range = 2;
    Split_area area( area_size, split_range );

    int num_x = (int)( area_size.x / split_range );
    int num_y = (int)( area_size.y / split_range );
    int num_z = (int)( area_size.z / split_range );

    ASSERT_EQ( num_x * num_y * num_z , area.cells.size() );
    
    uint curr_cell = 0;
    
    vec3d prev_border = {0, 0, 0};
    vec3d next_border = {0, 0, 0};

    for ( int k = 0; k < num_z; ++k ) {
        if ( k == num_z - 1 ) {
            next_border.z = area_size.z;
        } else {
            next_border.z += split_range;
        }

        for ( int j = 0; j < num_y; ++j ) {
            if ( j == num_y - 1 ) {
                next_border.y = area_size.y;
            } else {
                next_border.y += split_range;
            }
            for ( int i = 0; i < num_x; ++i ) {
                if ( i == num_x - 1 ) {
                    next_border.x = area_size.x;
                } else {
                    next_border.x += split_range;
                }

                ASSERT_EQ( prev_border, area.cells[curr_cell].left_border );
                ASSERT_EQ( next_border, area.cells[curr_cell].right_border );

                prev_border.x = next_border.x;

                curr_cell++;
            }
            prev_border.x = 0;
            next_border.x = 0;
            prev_border.y  = next_border.y;
        }
        prev_border.y = 0;
        next_border.y = 0;
        prev_border.z  = next_border.z;
    }

}

TEST(Split_area_borders, test_1x1x1){
    EXPECT_THROW( test_area_cells_borders(1, 1, 1), std::invalid_argument );
}
TEST(Split_area_borders, test_2x2x2){
    test_area_cells_borders(2, 2, 2);
}
TEST(Split_area_borders, test_5x5x5){
    test_area_cells_borders(5, 5, 5);
}
TEST(Split_area_borders, test_100x100x100){
    test_area_cells_borders(100, 100, 100);
}
TEST(Split_area_borders, test_1000x200x500){
    test_area_cells_borders(1000, 200, 500);
}
